#pragma once
#include "../Data_grid.h"
#include "../../../src_config/configUI.h"
#include "../../../src_algorithms/src_basics/dataStructAlg.h"
#include "../../../src_algorithms/src_PPDT/Router.h"		//寻路算法


class AlgorithmLink_grid {
public:
	AlgorithmLink_grid(Data_grid* data, ConfigUI* config)
		:m_data(data), m_config(config) {
	}
	~AlgorithmLink_grid() {}

	// 1.1 寻路部分
	void routingRunBegin();
	void routingRun(bool runInit = true, bool runPahtFinding = true);
	
	// 1.2 推线部分
	bool pushLineRun(const QPointF& offset, const bool inGreed, const bool postOn);
	void pushLineRunBegin(LineUI& line, std::vector<LineUI>& lines);		//设置算法数据，算法执行的起点

	bool pushPinRun(const QPointF& offset, bool inGreed = false);
	void pushPinRunBegin(QPointF pt, std::vector<LineUI>& lines);			//设置算法数据，算法执行的起点


private:
	Data_grid* m_data;
	ConfigUI* m_config;
	SelectedTarget * m_target = nullptr; //const
	std::vector<LineUI>* m_ui_wires = nullptr;
	//寻路
	vector<vector<NodePoint>> m_ptArr;		// 读取的地图数据
	vector<pair<NodePoint, NodePoint>> m_Pins;	// 读取的起点、终点数据
	//推线
	LineUI m_selectLine;
	std::vector<Line> m_beginLines;					//算法的初始输入数据，每次算法运行，都以此数据为基础
	QPointF m_selectPt;

private:
	void setRoutingResultData(Router& router);
	bool setPushLineData(std::vector<Line>& polyLines_input, Line& line_input, Point& offset_input, const QPointF& offset_ui);
	void pushLineDataUpdate(std::vector<Line>& polyLines_input);			//算法执行结束，更新数据
	bool setPushPinData(std::vector<Line>& polyLines_input, Point& pt_input, Point& offset_input, const QPointF& offset_ui);

};